import request from '@/utils/request'

// 角色分页
export function getRoleList(query) {
  return request({
    url: '/system/role/paging',
    method: 'get',
    params: query
  })
}

// 所有角色
export function getRoleAll(query) {
  return request({
    url: '/system/role/all',
    method: 'get',
    params: query
  })
}

// 所有角色
export function listEnterpeiseRole(params) {
  return request({
    url: '/system/role/listEnterpeiseRole',
    method: 'get',
    params
  })
}

export function deleteRole(subRoleId) {
  return request({
    url: '/system/role/delete',
    method: 'post',
    params: { subRoleId }
  })
}

export function saveRole(role) {
  return request({
    url: '/system/role/save',
    method: 'post',
    data: role
  })
}

// 启用，禁用角色
export function updateRoleStatus(subRoleId, status) {
  return request({
    url: '/system/role/updateRoleStatus',
    method: 'post',
    params: { subRoleId, status }
  })
}

// 批量启用，禁用角色
export function batUpdateStatus(roleIds, status) {
  return request({
    url: '/system/role/batUpdateStatus',
    method: 'post',
    data: { roleIds, status }
  })
}

// 批量删除角色
export function batDelete(roleIds) {
  return request({
    url: '/system/role/batDelete',
    method: 'post',
    data: { roleIds }
  })
}

// 按角色查询权限id
export function getPermissions(subRoleId) {
  if (!subRoleId) {
    return false
  }
  return request({
    url: '/system/role/getPermissions',
    method: 'get',
    params: { subRoleId }
  })
}

// 保存角色权限
export function saveRolePermissions(role) {
  return request({
    url: '/system/role/saveRolePermissions',
    method: 'post',
    data: role
  })
}
